#ifndef __MulticastUdpSocket_h__
#define __MulticastUdpSocket_h__

#include <base/types.h>
#include "IpSocket.h"

#include <string>

namespace Greatewall
{
    namespace Network
    {
        class MulticastUdpSocket : public IpSocket
        {
        public:
            enum MCMode
            {
                RECV,
                SEND
            };
            MulticastUdpSocket(SocketEventMonitor& monitor, SysSockHandler hdl = -1)
                : IpSocket(monitor, hdl)
                , _joined(false)
            {}

            virtual ~MulticastUdpSocket()
            {}

            virtual void
            handleInbound() = 0;

            virtual bool
            handleOutbound() = 0;

            virtual bool
            send(const char* buf, ssize_t& size, bool non_block=true);

            virtual bool
            recv(char*& buf, ssize_t& size, bool non_block=true);

            static SysSockHandler
            createMcUdpSock();

            bool
            initMcUdpSock(std::string& mc, short port, std::string& netif, MCMode mode);

            bool
            join();

            bool
            drop();

            virtual void
            close();

        private:
            std::string _mc;
            short       _port;
            std::string _netif;
            MCMode      _mode;
            sockaddr_in _in;
            sockaddr_in _out;
            bool        _joined;
        };
    }
}
#endif
